package net.orange.architecture.process;

import java.util.Collection;

import net.orange.architecture.db.Conditions;
import net.orange.architecture.db.IObjectManager;
import net.orange.architecture.db.ListConditions;
import net.orange.architecture.model.BaseValueObject;

/**
 * The interface of business logical delegate object, to retrieve , save ,
 * remove or process other operation for the persistency object.Every business
 * logical object should be extended from the base value object.
 */
public interface IBaseProcess {
	/**
	 * Get the database access object.
	 * 
	 * @return The database access object.
	 * @throws Exception
	 */
	public IObjectManager getDao() throws Exception;

	/**
	 * Set the database access object.
	 * 
	 * @param dao
	 *            The date access object
	 * @throws Exception
	 */
	public void setDao(IObjectManager dao) throws Exception;

	/**
	 * Retrieve the value object collection according the list conditions.
	 * 
	 * @param cds
	 *            The list conditions.
	 * @return The value object collection.
	 * @throws Exception
	 */
	public Collection list(ListConditions cds) throws Exception;

	/**
	 * Retrieve the value object collection according the list conditions.
	 * 
	 * @param cds
	 *            The list conditions.
	 * @return The value object collection.
	 * @throws Exception
	 */
	public Collection listAll(Conditions cds) throws Exception;

	/**
	 * Retrieve the value object collections (all records).
	 * 
	 * @return The value object collection.
	 * @throws Exception
	 */
	public Collection listAll() throws Exception;

	/**
	 * Retrieve the value object according the object id.
	 * 
	 * @param id
	 *            The object id
	 * @return The value object
	 * @throws Exception
	 */
	public BaseValueObject find(long id) throws Exception;

	/**
	 * Retrieve the value object according the object code.
	 * 
	 * @param field
	 *            The object code's field name.
	 * @param code
	 *            The object code.
	 * @return The value object
	 * @throws Exception
	 */
	public BaseValueObject find(String field, String code) throws Exception;

	/**
	 * Create the persistency value object object in database.
	 * 
	 * @param The
	 *            value object
	 * @return Whether success.
	 * @throws Exception
	 */
	public boolean insert(BaseValueObject bvo) throws Exception;

	/**
	 * Update the persistency value object object in database.
	 * 
	 * @param The
	 *            value object
	 * @return Whether success.
	 * @throws Exception
	 */
	public boolean update(BaseValueObject bvo) throws Exception;

	/**
	 * Remove the persistency value object object in database.
	 * 
	 * @param id
	 *            The object id.
	 * @return Whether success.
	 * @throws Exception
	 */
	public boolean delete(BaseValueObject bvo) throws Exception;

	/**
	 * Validation the object is right
	 * 
	 * @param bvo
	 *            The value object need the validate.
	 * @param n
	 *            Whether is the new object.
	 * @param msg
	 *            The error message return.
	 * @return Whether pass the validation.
	 * @throws Exception
	 */
	public boolean checkSave(BaseValueObject bvo, boolean n,
			Collection<String> msg) throws Exception;

	/**
	 * Check whether can deleted this object.
	 * 
	 * @param bvo
	 *            The object.
	 * @param msg
	 *            The message return.
	 * @return whether can deleted this object.
	 */
	public boolean checkDelete(BaseValueObject bvo, Collection<String> msg)
			throws Exception;
}
